//
//  MALHandler.h
//  iMAL
//
//  Created by Stefano Pigozzi on 1/30/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#include <stdlib.h>
#import <Cocoa/Cocoa.h>
#import <RegexKit/RegexKit.h>
#import "NSManagedObjectContext+FastFetch.h"
#import "iMAL_AppDelegate.h"

// login state
typedef enum loginTag {
	kNotLoggedIn = 0,
	kLoggedIn = 1,
	kErrorLoggingIn = -1
} Login;

@interface MALHandler : NSObject {
	IBOutlet NSWindow * progressSheet;
	
	NSString * user;
	NSString * password;
	NSString * url;
	NSMutableData * responseData;
	NSString * requestURL;
	NSString * absoluteRequestURL;
	
	IBOutlet iMAL_AppDelegate * app_delegate;
	
	NSNumber * progressMaximum;
	NSNumber * progressCurrent;
	NSString * progressMessage;
	
	NSOperationQueue * scheduledOperations;
	
	Login loggedInState;
}

@property (retain) NSString * user;
@property (retain) NSString * password;
@property (retain) NSString * url;
@property (retain) NSString * requestURL;
@property (retain) NSString * absoluteRequestURL;

@property (retain) iMAL_AppDelegate * app_delegate;
@property (retain) NSWindow * progressSheet;

@property (retain) NSNumber * progressMaximum;
@property (retain) NSNumber * progressCurrent;
@property (retain) NSString * progressMessage;

@property (retain) NSOperationQueue * scheduledOperations;

@property (assign) Login loggedInState;

- (void) login;
- (BOOL) isLoggedIn;
- (void) logout;

- (void) post:(NSString *) resource withData:(NSString *) data;
- (void) get:(NSString *) resource;
- (void) getURL:(NSString *)absolute_url;
- (void) import;
- (void) deep_import;
- (void) createFolders;

- (void) hideProgressSheet;

@end
